package com.deng.etl.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Date;

import com.deng.common.SQLHelper;
import com.deng.etl.common.EtlAuto;
import com.deng.util.DateTools;

public class OperateMoveToBack extends SQLHelper {

	public static String stat_time;
	public static int dispense_id;
	public int operateMoveToBackByOperateId(String stat_time,int dispense_id){
		try{
			OperateMoveToBack.stat_time = stat_time;
			OperateMoveToBack.dispense_id = dispense_id;
			new Thread(){
				@Override
				public void run() {					
					try{
						Connection conn = new EtlAuto().getTargetConn();
				        String dt = DateTools.dtsWithTimeS0(new Date());
						String sql = "insert into t_org_operate_item_count_month_backup" +
								"	(backup_time,stat_time,create_time,operate_code," +
								"	operate_name,item_code,item_id," +
								"	item_name,chengben_type,fee)" +
								"	select '"+dt+"',stat_time,create_time,operate_code," +
								"	operate_name,item_code,item_id," +
								"	item_name,chengben_type,fee" +
								"	from t_org_operate_item_count_month" +
								"	where stat_time = '"+OperateMoveToBack.stat_time+"'" +
								"	and operate_code in (select original_id " +
								"	from t_sys_stat_operate_department_vs_original_department " +
								"	where operate_id = "+OperateMoveToBack.dispense_id+")";
						System.out.println("备份数据抽取：  "+sql);
						updateData(conn, sql);
					}catch(Exception ex){
						ex.printStackTrace();
					}									
				}
			}.start();
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return 0;
	}
}
